<template>
   <van-icon color="#777"
   :name="value?'star':'star-o' "
   :class="value ? 'active' : ''"
   @click="Load"
   :loading="loading"
    />
</template>

<script>
import { getCollections, delCollections } from '@/api/article'
export default {
  data () {
    return {
      loading: false
    }
  },
  props: {
    value: {
      type: Boolean,
      required: true
    },
    collectionId: {
      type: [String, Number, Object],
      required: true
    }
  },
  components: {},
  created () {
  },
  computed: {},
  methods: {
    async Load () {
      this.loading = true
      try {
        if (this.value) { // 已经收藏
          await delCollections(this.collectionId)
        } else {
          await getCollections(this.collectionId)
        }
        this.$emit('input', !this.value)
        this.$toast.success(!this.value ? '收藏成功' : '取消收藏')
      } catch (err) {
        console.log('请求失败')
        this.$toast('操作失败，请重试')
      }
      this.loading = false
    }
  }
}
</script>

<style lang='less' scoped>
.active{
    color: orange !important;
}
</style>
